import axios from 'axios'
import { APP_BASE_URL, AUTH_BASE_URL } from './constants'

export const API = axios.create({
  baseURL: APP_BASE_URL,
  withCredentials: false
})

export const setHeader = (value, key = 'Authorization') => {
  API.defaults.headers.common[key] = `Bearer ${value}`
  AUTH.defaults.headers.common[key] = `Bearer ${value}`
}

export const removeHeader = key => {
  delete API.defaults.headers.common[key]
  delete AUTH.defaults.headers.common[key]
}

export const AUTH = axios.create({
  baseURL: AUTH_BASE_URL,
  withCredentials: false
})
